package top.wshape1.rpc.compress;

import lombok.extern.slf4j.Slf4j;
import org.xerial.snappy.Snappy;

import java.io.IOException;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2024-02-20
 */

@Slf4j
public class SnappyCompressor implements Compressor {
    @Override
    public byte[] compress(byte[] data) {
        try {
            return Snappy.compress(data);
        } catch (IOException e) {
            log.error("snappy compress error", e);
            throw new RuntimeException(e);
        }
    }

    @Override
    public byte[] decompress(byte[] data) {
        try {
            return Snappy.uncompress(data);
        } catch (IOException e) {
            log.error("snappy decompress error", e);
            throw new RuntimeException(e);
        }
    }
}
